package com.airconditioner.sales.activity;

import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ExpandableListView;

import com.airconditioner.sales.R;
import com.airconditioner.sales.adapter.InputHouseTypeAdapter;
import com.airconditioner.sales.view.InputHouseSizeDialog;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;


/**
 * 作者：shuizi_wade on 2017/1/21 17:12
 * 邮箱：674618016@qq.com
 */
@ContentView(R.layout.activity_input_house_type)
public class InputHouseTypeActivity extends BaseActivity {
    @ViewInject(R.id.input_house_exp)
    ExpandableListView listView;

    @Override
    public void init() {
        super.init();
        title_iv_back.setImageResource(R.mipmap.titlebar_back_black);
        title_iv_back.setBackgroundColor(getResources().getColor(R.color.white_color));
        title_relate_layout.setBackgroundColor(getResources().getColor(R.color.white_color));
        Drawable drawable = getResources().getDrawable(R.mipmap.titlebar_js);
        title_tv_right.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
        title_tv_right.setText(R.string.calculate);
        InputHouseTypeAdapter adapter = new InputHouseTypeAdapter(context);
        listView.setGroupIndicator(null);
        title_tv_title.setText(R.string.input_house_type);
        listView.setAdapter(adapter);
        listView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
            @Override
            public void onGroupExpand(int groupPosition) {
                int count = listView.getExpandableListAdapter().getGroupCount();
                boolean isEmpty = false;
                for (int i = 0; i < count; i++) {
                    if (groupPosition == 0) {
                        listView.collapseGroup(i);
                        isEmpty = true;
                    } else {
                        if (groupPosition != i) // 关闭其他分组
                            listView.collapseGroup(i);
                        isEmpty = false;
                    }
                }
                if (isEmpty) {
                    InputHouseSizeDialog.INSTANCE.dialog(context, new InputHouseSizeDialog.Dialogcallback() {
                        @Override
                        public void getSize(String content) {
                            senToa(content);
                        }
                    });
                }
            }
        });
        listView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
                senToa("父项：" + groupPosition + "；子项：" + childPosition);
                return false;
            }
        });
    }

    @Event({R.id.title_iv_back, R.id.title_tv_right})
    private void getEvent(View view) {
        switch (view.getId()) {
            case R.id.title_iv_back:
                finish();
                break;
            case R.id.title_tv_right:
                jumpActvity(GatherCalculateActivity.class);
                break;
        }
    }
}
